import fetch from './fetch.js'
import { Tservice } from './fetch.js';
const pageSize = 10;
// 获取首页信息
export function getHomeData() {
    return fetch({
        url: '/index/h5',
        method: 'get'
    });
}

export function getFirstCategory () {
	return fetch({
        url: '/goodsCategory',
        method: 'get'
    });
}

export function getCode (tel) { //获取验证码
 		return fetch({
 			url: '/userLogins/sendCode?phone='+tel,
			method: 'get',
	});
}

const apiService = {
	getHomeData: function() {
	    return fetch({
	        url: '/index/h5',
	        method: 'get'
	    });
	},
	getFirstCategory: function () {
		return fetch({
	        url: '/goodsCategory',
	        method: 'get'
	    });
	},
	getCode: (params) => fetch({    //获取验证码
	        url: '/userLogins/sendCode?phone='+params.tel+'&random='+ params.random+ '&code='+ params.code,
	        method: 'get'
	    }),
	getPwdCode: (tel) => fetch({   //获取忘记密码验证码
			url: 'userLogins/sendUpdPwdCode?phone=' + tel,
			method: 'get'
		}),
	getPrepare: (tel) => fetch({   //检验是否需要弹出图片验证码
			url: '/userLogins/prepareSend?phone='+tel,
	        method: 'get'
		}),
	getNECaptcha: (params) => fetch({
			url: '/userLogins/send?phone='+params.tel+'&NECaptchaValidate='+params.randomCode,
			method: 'get'
		}),
	verify: (params) => fetch({  //验证码登录
			url: '/userLogins/sms/login',
			method: 'post',
			data: params
		}),
	pwdLogin: (params) => fetch({  //密码登录
			url: '/userLogins/login',
			method: 'post',
			data: params
	}),
	pwdAdd: (params) => fetch({  //密码登录
			url: '/userLogins/addPassword',
			method: 'post',
			data: params
	}),
	getForgetPwd: (params) => fetch({   //找回密码
			url: '/userLogins/findPassword',
			method: 'post',
			data: params
	}),
	getUserInfo: () => Tservice({   //获取用户信息
			url: '/users/personalInformation',
			method: 'get'
	}),
	getUserInfo2: () => fetch({   //获取用户信息
			url: '/users/personalInformation',
			method: 'get'
	}),
	genderOrpicChange: (params) => fetch({   //修改头像，性别
			url: '/users/baseInfo',
			method: 'put',
			data: params
	}),
	getPicParameter: (type) => fetch({   //获取图片上传参数
			url: '/aliFileUpload/stsToken/'+type,
			method: 'get'
	}),
	resetPwd: (params) => fetch({
			url: '/userLogins/updatePassword',   //修改密码
			method: 'patch',
			data: params
	}),
	feedback: (params) => fetch({   //反馈
			url: '/feedback/feedbackInfo',
			method: 'post',
			data: params
	}),
	getCodeUrl: () => fetch({   //邀请好友二维码
			url: '/users/toCodeView',
			method: 'get'
	}),
	getBusiness: () => fetch({   //获取收藏商品列表
			url: '/goodsCollects/me',
			method: 'get'
	}),
	getShop: () => fetch({      //获取收藏店铺列表
			url: '/merchantCollects/me',
			method: 'get'
	}),
	getContact: ()=> fetch({    //获取收货地址列表
			url: '/userContacts',
			method: 'get'
	}),
	cancelBusiness: (id) => fetch({   //取消商品收藏
		url: "/goodsCollects/"+id,
		method: 'delete'
	}),
	postNewContact: (params) => fetch({    //新增收货地址
			url: '/userContacts',
			method: 'post',
			data: params
	}),
	getContactByid: (id) => fetch({   //获取单个收货地址
			url: '/userContacts/'+id,
			method: 'get'
	}),
	postEditContact: (id,params) => fetch({    //修改地址
			url: "/userContacts/"+id,
			data: params,
			method: 'put'
	}),
	addEditContact: (params) => fetch({    //新增收货地址
			url: "/userContacts",
			data: params,
			method: 'post'
	}),
	refuseCompensate: (orderId, params) => fetch({     //拒绝赔偿
		url: '/order/refuseCompensate/' + orderId,
		data: params,
		method: 'put'
	}),
	commitEvaluate: (orderId, params) => fetch({    //提交评价
		url: "/comments/comment/"+orderId,
		data: params,
		method: 'post'
	}),
	getMyJudge: (state) => fetch({    //获取评价列表
		url: "/comments/myCommentList/" + state,
		method: 'get'
	}),
	applyServiceOperate: (orderId, state, params) =>fetch({   //提交换货,退还，维修申请 applyExchange applyReturn applyRepair
		url: "/serviceOrders/"+state+"/"+orderId,
		data: params,
		method: 'post'
	}),
	getInvitePerson: (recommandCode) =>fetch({   //根据邀请码，获取邀请人
		url: "/users/findInviteUser?recomondCode="+recommandCode,
		method: 'get'
	}),
	loginUser: (params) =>fetch({  //注册
		url: "/userLogins/regist",
		data: params,
		method: 'post'
	}),
	getRedDotInfo: () => Tservice({   //获取数量
		url: '/reddot/getRedDotInfo',
		method: 'get'
	})
}
export default apiService;

export function getHelpProblem() {
	return fetch({
		url: "/user/faq/get",
		method: 'get'
	})
}

export function  getAwards(params) {  //获取优惠卷
	return fetch({
		url: "/user/bonus/" + params.state + "/list?pageNum=" + params.pageNum + "&pageSize=10",
		method: 'get'
	})

}

export function getOrder(params) {   //获取订单
	return fetch({
		url: "/order/"+params.state+"/list?pageNum="+params.pageNum+"&pageSize=10",
        method: 'get'
    });
}

export function getDataByFirstCategory (id) {
	return fetch ({
		url: "/goods?listType=three&categoryId="+id,
		method: 'get'
	})
}

export function getChooseData(id){
    return fetch ({
        url: '/goods/'+ id,
        method: 'get'
    })
}

export function getCollectData(id,num){
    return fetch ({
        url: '/index/listGoods/' + id +"?pageNum=" + num + "&pageSize=" + pageSize,
        method: 'get'
    })
}
export function getSearchData(searchString,num,orderBy,desc){
    let url = '/openSearch/goodsSearch?search=' + searchString + "&pageNum=" + num + "&pageSize=" + pageSize;
    if(orderBy){
        url += "&orderBy="  + orderBy;
    }
    if(desc){
        url += "&desc=" + desc;
    }
    return fetch ({
        url: url,
        method: 'get'
    })
}
export function getParamDetail(id){
    return fetch ({
        url: "/goods/parameters/group?goodsId=" + id,
        method: 'get'
    })
}

export function getRemarks (id,num){
    return fetch ({
        url: "/comments/goodsCommentList/" + id + "?pageNum=" + num + "&pageSize=" + pageSize,
        method: 'get'
    })
}

// 查询价格
export function getPrice (queries){
    return fetch ({
        url: "/goods/goodsPrice" + queries,
        method: 'get'
    })
}

export function getOrderDetail(orderId) {   //获取租赁订单详情
	return fetch({
		url: "/order/" + orderId,
		method: 'get'
	})
}

export function cancelOrder(orderId, params) {    //取消订单
	return fetch({
		url: "/order/cancelLeaseOrder/" + orderId,
		data: params,
		method: 'put'
	})
}

export function getPayDetail(orderId) {    //获取支付详情
	return fetch({
		url: "/order/toPay/"+orderId,
		method: 'get'
	})
}

export function getCoupon(goodsId, price) {    //获取过滤的优惠券
	return fetch({
		url: "/user/bonus/"+goodsId+"/unused?price=" + price,
		method: 'get'
	})
}

export function doPayOrder(channel, payType, orderId, params) {    //订单支付
	return fetch({
		url: "/order/payment/" + channel + "/" + payType + "/" + orderId,
		data: params,
		method: "post"
	})
}

export function doPayAccount(channel, payType, orderId, params) {  //帐期支付
	return fetch({
		url: "/order/bill/payment/"+channel+"/"+payType+"/"+orderId,
		data: params,
		method: 'post'
	})
}

export function getLogisticsInfo(orderId, type) {  //获取物流信息
	return fetch({
		url: '/order/logisticsInfo/'+type+"/"+ orderId,
		method: 'get'
	})
}


export function getProofInfo(orderId) {  //用户拒绝赔偿举证基本信息
	return fetch({
		url: '/order/proofInfo/' + orderId,
		method: 'get'
	})
}

export function doPayReturnOverdue(channel, payType, orderId, params) {    //退还逾期支付
	return fetch({
		url: "/order/returnOverdue/payment/"+channel+"/"+payType+"/"+orderId,
		data: params,
		method: 'post'
	})
}

export function doReturn(orderId, params){  //还机操作
	return fetch({
		url: "/order/goodsBack/" + orderId,
		data: params,
		method: 'put'
	})
}

export function getLogisticsCompany(){   //获取物流公司列表
	return fetch({
		url: "/logistics/company/list",
		method: 'get'
	})
}

export function pressDelivery(orderId) {    //催促发货
	return fetch({
		url: "/order/reminder/"+ orderId,
		method: 'put'
	})
}

export function doPayCompensate(channel, payType, orderId, params) {     //赔偿支付
	return fetch({
		url: "/order/compensate/payment/"+channel+"/"+payType+"/"+orderId,
		data: params,
		method: 'post'
	})
}


export function goGoodsBack(orderId, params) {    //还机
	return fetch({
		url: "/order/goodsBack/" + orderId,
		data: params,
		method: 'put'
	})
}


export function getMyJudge(state){    //获取评价列表
	return fetch({
		url: "/comments/myCommentList/" + state,
		method: 'get'
	})
}

export function getJudgeDetail(orderId){    //获取评价详情
	return fetch({
		url: "/comments/"+orderId,
		method: 'get'
	})
}

export function getServiceOrders(params) {   //获取服务订单  (tab:repair 维修  return 退货  exchange 换货)
	return fetch({
		url: "/serviceOrders/"+params.state+"/canApplyList"+"?pageNum=" + params.pageNum+"&pageSize=10",
		method: 'get'
	})
}

export function applyServiceOperate(orderId, state, params) {   //提交换货,退还，维修申请 applyExchange applyReturn applyRepair
	return fetch({
		url: "/serviceOrders/"+state+"/"+orderId,
		data: params,
		method: 'post'
	})
}

export function getPlatContent() {
	return fetch({
		url: "/agreement/platform",
		method: 'get'
	})
}

export function getDiscoverBanner() {
	return fetch({
		url: "/find/listFind/H5_SHOW",
		method: 'get'
	})
}
// 获取活动信息
export function getPromotion(num,type) {
	return fetch({
		url: '/find/' + type + "?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}


export function getInfoContent(id) {
	return fetch({
		url: "/find/info/" + id,
		method: 'get'
	})
}

export function getAllCate() {
	return fetch({
		url: "/goodsCategory/getAllCategoryAndType",
		method: 'get'
	})
}

export function getSecondData(id,num) {
	return fetch({
		url: "/goods/searchList?typeId=" + id + "&pageSize=" + pageSize + "&pageNum=" + num,
		method: 'get'
	})
}

// 检查用户权限
export function checkPriority(param) {
	return fetch({
		url: '/users/zhimaCreditScoreBrief',
		data: param,
		method: 'post'
	})
}

export function getInvitePer() {  //获取邀请人列表
	return fetch({
		url: "/users/userInviteRecodeList",
		method: 'get'
	})
}

export function getUserCheckIn(){   //检验是否签到
	return fetch({
		url: "/userCheckIn/check",
		method: "get"
	})
}

export function addUserCheckIn() {   //签到
	return fetch({
		url: "/userCheckIn/add",
		method: 'post'
	})
}
// 确认下单
export function makeOrder(param) {
	return fetch({
		url: '/order/lease/reservation',
		data: param,
		method: 'post'
	})
}

// 预授权接口
export function goAuthor(param) {
	return fetch({
		url: '/order/lease/reservation',
		data: param,
		method: 'post'
	})
}

// 获取所有优惠券
export function getAllCoupon() {
	return Tservice({
		url: "/user/bonus/unused/list?pageNum=1&pageSize=100",
		method: 'get'
	})
}
// 查询是否收藏
export function checkFavor(merid,id) {
	return Tservice({
		url: "/goodsCollects/isCollect/" + merid + "/" + id,
		method: 'get'
	})
}
// 收藏商品
export function doFavor(merid,id,params) {
	return fetch({
		url: "/goodsCollects/collect/" + merid + "/" + id,
		data: params,
		method: 'post'
	})
}


// 获取消息
export function getMessage(num) {
	return fetch({
		url: "/inmail/list?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}
// 更新消息
export function updateMessage(param) {
	return fetch({
		url: "/inmail/update",
		data: param,
		method: 'put'
	})
}
// 查询是否有消息
export function checkMessage() {
	return Tservice({
		url: "/inmail/getIsRead",
		method: 'get'
	})
}

// 获取维修列表
export function getRepairList(num) {
	return fetch({
		url: "/serviceOrders/repair/canApplyList?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}
// 查询是否购买保险
export function checkInsurance(id) {
	return fetch({
		url: "/serviceOrders/isBuyInsurance/" + id,
		method: 'get'
	})
}
// 发送维修申请
export function sendRepair(id,param) {
	return fetch({
		url: "/serviceOrders/applyRepair/" + id,
		data: param,
		method: 'post'
	})
}
// 获取售后申请记录
export function getServiceList(num) {
	return fetch({
		url: "/serviceOrders/applyResultList?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}
// 取消申请记录
export function goCancelRequest(id,param) {
	return fetch({
		url: "/serviceOrders/cancelApply/" + id,
		data: param,
		method: 'put'
	})
}
// 获取商家信息
export function getMerchantInfo(id) {
	return fetch({
		url: "/serviceOrders/toSends/" + id + "?serviceOrderId=" + id,
		method: 'get'
	})
}

// 服务订单发货
export function sendServiceGood(id,param) {
	return fetch({
		url: "/serviceOrders/sends/" + id,
		data: param,
		method: 'post'
	})
}

// 订单租赁协议
export function getProtocolOrder(orderId) {
	return fetch({
		url: "/order/ismtAgmtToView/" + orderId,
		method: 'get'
	})
}

// 上上签合同签约
export function putBestSign(orderId, params) {
	return fetch({
		url: '/bestSign/' + orderId,
		data: params,
		method: 'put'
	})
}

export function getServiceOrdersLogisticsInfo(orderId, channel) {    //获取服务订单物流详情
	return fetch({
		url: "/serviceOrders/logisticsInfo/" + channel + "/" + orderId,
		method: 'get'
	})
}

// 查询刷脸结果

export function queryZhima(zmtoken) {
	return fetch({
		url: "/users/queryZhimaCertResult/" + zmtoken,
		method: 'get'
	})
}

// 续租接口
// 续租列表
export function getReletList(index,num) {
	let tab
	if(index == 1){
		tab = "appliable";
	}else {
		tab = "applied";
	}
	return fetch({
		url: "/order/relet/" + tab + "/list?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}
// 续租详情
export function getReletDetail(id) {
	return fetch({
		url: "/order/toRelet/" + id,
		method: 'get'
	})
}
// 提交续租
export function submitRelet(param,id) {
	return fetch({
		url: "/order/" + id + "/relet",
		data: param,
		method: 'put'
	})
}

// 取消续租申请
export function cancelReletReq(param,id) {
	return fetch({
		url: "/order/relet/" + id + "/cancel",
		data: param,
		method: 'put'
	})
}

// 获取续租进度信息
export function getReletProgress(id) {
	return fetch({
		url: "/order/relet/" + id,
		method: 'get'
	})
}

// 空协议接口
export function getBlankProtocal() {
	return fetch({
		url: "/common/ismtAgmtToView",
		method: 'get'
	})
}


//买断接口
export function getBuyFinshList(index, num) {
	let tab
	if(index == 1){
		tab = "appliable";
	}else {
		tab = "applied";
	}
	return fetch({
		url: "/order/buyout/" + tab + "/list?pageNum=" + num + "&pageSize=" + pageSize,
		method: 'get'
	})
}

//买断支付信息
export function getBuyFinishPayDetail(orderId) {
	return fetch({
		url: "/order/toBuyout/" + orderId,
		method: 'get'
	})
}
//订单申请买断
export function applyBuyFinish(orderId, params) {
	return fetch({
		url: "/order/"+orderId+"/buyout",
		data: params,
		method: 'put'
	})
}
//买断支付
export function submitBuyFinish(urlParams, params) {
	return fetch({
		url: "/order/buyout/payment/"+ urlParams.channel +"/"+ urlParams.payType + "/" + urlParams.orderId,
		data: params,
		method: 'post'
	})
}

//取消买断
export function buyOutCancel(id) {
	return fetch({
		url: "/order/buyout/"+ id + "/cancel",
		method: 'put'
	})
}

//获取买断信息
export function getBuyFinishDetail(id) {
	return fetch({
		url: "/order/buyout/" + id,
		method: 'get'
	})
}

//通用活动优惠券领取
export function receiveCommonBonus(data) {
  return Tservice({
    url: "/user/bonus/receiveCommon",
    method: 'post',
    data:data,
  })
}

//获取用户信息
export function getUserInfomation(){
  return Tservice({
    url: "/users/personalInformation",
    method: 'get',
  })
}
